/*** "なんでも作っちゃう、かも" Scroll Animation
 * by arms22 <http://arms22.blog91.fc2.com/>
 * 
 * Demonstrates the use of the Dots library
 * 
 * Matrix  Arduino
 * 1  R5 -> 17(analog 3)
 * 2  R7 -> 16(analog 2)
 * 3  C2 -> 15(analog 1)
 * 4  C3 -> 14(analog 0)
 * 5  R8 -> 13
 * 6  C5 -> 12
 * 7  R6 -> 11
 * 8  R3 -> 10
 * 9  R1 -> 9
 * 10 C4 -> 8
 * 11 C6 -> 7
 * 12 R4 -> 6
 * 13 C1 -> 5
 * 14 R2 -> 4
 * 15 C7 -> 3
 * 16 C8 -> 2
 */

#include <Dots.h>

Dots myDots = Dots();

byte imageData[] = {
  // な
  0b00110010,
  0b00001111,
  0b00000010,
  0b00100010,
  0b01010000,
  0b01111110,
  0b00010001,
  0b00010000,

  // ん
  0b01000000,
  0b00100000,
  0b00011000,
  0b00100110,
  0b01000000,
  0b01000000,
  0b00100000,
  0b00000000,

  // で
  0b00000010,
  0b00000010,
  0b00111010,
  0b01000110,
  0b01000010,
  0b00000001,
  0b00000001,
  0b00000000,

  // も
  0b00001010,
  0b00111111,
  0b01001010,
  0b01001010,
  0b01001010,
  0b00100000,
  0b00000000,
  0b00000000,

  // 作
  0b00000100,
  0b01111110,
  0b00000001,
  0b00000100,
  0b00000011,
  0b01111110,
  0b00010110,
  0b00010100,
  0b00000000,

  // っ
  0b00001000,
  0b01001000,
  0b01001000,
  0b00110000,
  0b00000000,

  // ち
  0b00000010,
  0b00010010,
  0b00001111,
  0b00001010,
  0b01001010,
  0b01001000,
  0b00110000,
  0b00000000,

  // ゃ
  0b00001000,
  0b00011110,
  0b01001000,
  0b00110000,
  0b00000000,

  // う
  0b00001000,
  0b00000101,
  0b01000101,
  0b01000100,
  0b00111000,
  0b00000000,
  0b00000000,

  // 、
  0b00100000,
  0b01000000,
  0b00000000,
  0b00000000,

  // か
  0b00100100,
  0b00011100,
  0b00000111,
  0b01000100,
  0b00111100,
  0b00000010,
  0b00001100,
  0b00000000,

  // も
  0b00001010,
  0b00111111,
  0b01001010,
  0b01001010,
  0b01001010,
  0b00100000,
  0b00000000,
  0b00000000,

  // 。
  0b01100000,
  0b01100000,
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000000,
};

int img_h = sizeof(imageData) / sizeof(imageData[0]);
int src_y = 0;

void setup()
{
  myDots.begin();
}

void loop()
{
  for(uint8_t i=0; i<8; i++){
    myDots.write(i, getImageLineData(src_y + i));
  }

  src_y++;
  if(src_y >= img_h){
    src_y = 0;
  }

  delay(100);
}

byte getImageLineData(int y)
{
  if(y >= img_h){
    y -= img_h;
  }
  return imageData[y];
}

